﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YJKArchUtils.Utils;
using YJKRevitView;

namespace YJKCarSlopingPath
{
	[Transaction(TransactionMode.Manual)]
	[Regeneration(RegenerationOption.Manual)]
	public class CmdCreateRamp : IExternalCommand
	{
		public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elems)
		{
			Result result;
			try
			{
				if (cmdData == null)
				{
					throw new System.ArgumentNullException("commandData");
				}
				CmdViewType types = (CmdViewType)3;
				if (SwitchView.SetUsableView(types, cmdData) != Autodesk.Revit.UI.Result.Succeeded)
				{
					result = Autodesk.Revit.UI.Result.Failed;
				}
				else
				{
					Document document = cmdData.Application.ActiveUIDocument.Document;
					HideWarningAndErroringKit @object = new HideWarningAndErroringKit(new List<string>
					{
						"create ramp"
					}, HideWarningAndErroringKit.HideKitEnum.HideWarning);
					cmdData.Application.Application.FailuresProcessing += @object.OnFailuresProcessing;
					if (!new RampManager(cmdData).Create())
					{
						result = Autodesk.Revit.UI.Result.Failed;
					}
					else
					{
						result = Autodesk.Revit.UI.Result.Succeeded;
					}
				}
			}
			catch (Exception ex)
			{
				msg = ex.Message;
				result = Autodesk.Revit.UI.Result.Failed;
			}
			return result;
		}
	}
}
